asm
  ld sp,$FFEF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"

dim eee as uinteger at $E012
dim seed as uinteger at $E014
dim ee0 as uinteger at $E010
dim ee1 as uinteger at $E01A
dim ee2 as uinteger at $E016
dim ee3 as uinteger at $E018

dim ecsp as ubyte at $E01C
dim ecsq as ubyte at $E01E
dim ex0 as uinteger at $E020
dim ey0 as uinteger at $E022
dim ej0 as uinteger at $E024
dim ej1 as uinteger at $E026

seed=127

sub egghuntputchar(txp1 as uinteger,typ1 as uinteger, tch1 as uinteger,tat1 as ubyte):
  poke uinteger $D000+(((typ1*64)+txp1)*2),tch1
  poke $C800+(typ1*64)+txp1,tat1
  end sub

for eee=$C000 to $DFFF
  seed=smsrnd(seed)
  poke eee,seed
  next

for ee0=0 to 29
  for ee1=0 to 47
    ee2=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    egghuntputchar(ee1+8,ee0+1,seed band 15,ee2)
    next:next

for ee0=0 to 15
  for ee1=0 to 15
    egghuntputchar(ee1+8+31,ee0+1+13,ee0*16+ee1,0)
    next:next

ex0=12:ey0=12
eee=0
do
egghuntputchar(8+1,1+1,48+((int(eee/10000)) mod 10),0)
egghuntputchar(8+2,1+1,48+((int(eee/1000)) mod 10),0)
egghuntputchar(8+3,1+1,48+((int(eee/100)) mod 10),0)
egghuntputchar(8+4,1+1,48+((int(eee/10)) mod 10),0)
egghuntputchar(8+5,1+1,48+(eee mod 10),0)

ee3=in($00) bxor $FF
egghuntputchar(8+3,1+3,48+((int(ee3/100)) mod 10),0)
egghuntputchar(8+4,1+3,48+((int(ee3/10)) mod 10),0)
egghuntputchar(8+5,1+3,48+(ee3 mod 10),0)

ee3=in($01) bxor $FF
egghuntputchar(8+3,1+4,48+((int(ee3/100)) mod 10),0)
egghuntputchar(8+4,1+4,48+((int(ee3/10)) mod 10),0)
egghuntputchar(8+5,1+4,48+(ee3 mod 10),0)

ee3=in($02) bxor $FF
egghuntputchar(8+3,1+5,48+((int(ee3/100)) mod 10),0)
egghuntputchar(8+4,1+5,48+((int(ee3/10)) mod 10),0)
egghuntputchar(8+5,1+5,48+(ee3 mod 10),0)

ex0=ex0+((ee3 band 16)/16)-((ee3 band 32)/32)
ey0=ey0+((ee3 band 64)/64)-((ee3 band 128)/128)
egghuntputchar(8+ex0,1+ey0,eee band $7F,0)

ee3=in($03) bxor $FF
egghuntputchar(8+3,1+6,48+((int(ee3/100)) mod 10),0)
egghuntputchar(8+4,1+6,48+((int(ee3/10)) mod 10),0)
egghuntputchar(8+5,1+6,48+(ee3 mod 10),0)

ee3=in($04) bxor $FF
egghuntputchar(8+3,1+7,48+((int(ee3/100)) mod 10),0)
egghuntputchar(8+4,1+7,48+((int(ee3/10)) mod 10),0)
egghuntputchar(8+5,1+7,48+(ee3 mod 10),0)

eee=eee+1
loop




do:loop

do
for eee=$C000 to $DFFF
  seed=smsrnd(seed)
  poke eee,seed
  next
loop

do:loop

'static ADDRESS_MAP_START( egghunt_map, AS_PROGRAM, 8, egghunt_state )
'AM_RANGE(0x0000, 0x7fff) AM_ROM
'AM_RANGE(0xc000, 0xc7ff) AM_RAM_DEVWRITE("palette", palette_device, write) AM_SHARE("palette")
'AM_RANGE(0xc800, 0xcfff) AM_RAM_WRITE(egghunt_atram_w) AM_SHARE("atram")
'AM_RANGE(0xd000, 0xdfff) AM_READWRITE(egghunt_bgram_r, egghunt_bgram_w)
'AM_RANGE(0xe000, 0xffff) AM_RAM
'ADDRESS_MAP_END

'static ADDRESS_MAP_START( io_map, AS_IO, 8, egghunt_state )
'ADDRESS_MAP_GLOBAL_MASK(0xff)
'AM_RANGE(0x00, 0x00) AM_READ_PORT("DSW1") AM_WRITE(egghunt_vidram_bank_w)
'AM_RANGE(0x01, 0x01) AM_READ_PORT("SYSTEM") AM_WRITE(egghunt_gfx_banking_w)
'AM_RANGE(0x02, 0x02) AM_READ_PORT("P1")
'AM_RANGE(0x03, 0x03) AM_READ_PORT("P2") AM_WRITE(egghunt_soundlatch_w)
'AM_RANGE(0x04, 0x04) AM_READ_PORT("DSW2")
'AM_RANGE(0x06, 0x06) AM_READ_PORT("UNK") AM_WRITENOP
'AM_RANGE(0x07, 0x07) AM_WRITENOP
'ADDRESS_MAP_END




